<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller\Api;

use App\Controller\AbstractController;
use App\Middleware\AuthMiddleware;
use App\Model\Message;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Middlewares([AuthMiddleware::class])]
#[Controller]
class MessageController extends AbstractController
{
    #[GetMapping(path: '/api/message/list')]
    public function list()
    {
        $list = Message::query()->get();
        $data['searchCount'] = true;
        $data['records'] = $list;
        return success($data);
    }

    #[PostMapping(path: '/api/message/add')]
    public function add()
    {
        $params = $this->request->all();
        Message::query()->create([
            'avatar' => $params['avatar'],
            'content' => $params['content'],
            'nickname' => $params['nickname']
        ]);
        return success();
    }

}
